package se.liu.oschi129.game.objects.blocks.breakable;

import se.liu.oschi129.animation.Animation;
import se.liu.oschi129.timer.Timer;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.objects.WorldMovableObject;

/**
 * This is an abstract class for block parts.
 * 
 * @author oschi129
 */
public abstract class ObjectBreakableBlockPart extends WorldMovableObject {

	// Once this timer is cool the object will be removed from the world
	private Timer timer;

	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public ObjectBreakableBlockPart(Animation animation, double x, double y) {
		super(Type.SOFT, animation, true, x, y, 8, 8);
		setHorizontalSpeed((Math.random()-0.5) * 8);
		setVerticalSpeed(- Math.random() * 8);
		setDepth(-1);
		timer = new Timer(8);
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	@Override public void performStepAction(World world) {
		if (getPhysicalRules() == null)
			setPhysicalRules(world.getPhysicalRules());
		if (timer.cool())
			world.removeObjectSynchronized(this);
		else {
			super.performStepAction(world);
			realizeGravity(world);
			timer.tick();
		}

	}

}
